home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr15 / rtag10.zip / ORBIT.RTA < prev    next >
Text File  |  1993-05-24  |  3KB  |  102 lines

  1. //  Orbital simulation.
  2. //  This is the control file for RTAG (Ray Tracing Animation Generator).
  3. //  Produced by Phillip H. Sherrod
  4.  
  5. //  ---  File declarations  ---
  6. bfile orbit            // Batch file is ORBIT.BAT
  7. //  ---  General simulation data  ---
  8. var numframes = 200
  9. var endtime = 200
  10. var timestep = .1
  11. var sf = 5            // Speed/distance factor
  12. //  ---  Planet orbital data  ---
  13. //  Planet 1
  14. var smaj1 = 6.443832        // Semi-major axis
  15. var smin1 = 5.780208        // Semi-minor axis
  16. var phase1 = 0            // Phase angle
  17. //  Planet 2
  18. var smaj2 = 9.028421
  19. var smin2 = 8.516810
  20. var phase2 = 0
  21. //  Planet 3
  22. var smaj3 = 12.960591
  23. var smin3 = 11.520525
  24. var phase3 = 0
  25. //  Moon around planet 3
  26. var mr = 2            // Radius of moon's orbit
  27. var phasem = 60            // Orbital position angle when time = 0.
  28. var moonfreq = 5        // Number of times moon orbits
  29. //  ---  Other variables  ---
  30. var x1,z1,f1,s1,d1
  31. var x2,z2,f2,s2,d2
  32. var x3,z3,f3,s3,d3
  33. var xm,zm,sm
  34. var time,frametime,framestep
  35.  
  36. //  ---  Initialization  ---
  37. //  Compute position of foci (along x axis)
  38. f1 = sqrt(smaj1^2 - smin1^2)
  39. f2 = sqrt(smaj2^2 - smin2^2)
  40. f3 = sqrt(smaj3^2 - smin3^2)
  41. //  Angular velocity of moon
  42. sm = (360 * moonfreq) / endtime
  43. //  Compute time between frames
  44. framestep = endtime / numframes
  45. //  ---  Simulation procedure  ---
  46. for time = 0 while (time < endtime) step timestep do
  47.     //  Compute current position
  48.     x1 = f1 + smaj1 * cos(phase1)
  49.     z1 = smin1 * sin(phase1)
  50.     x2 = f2 + smaj2 * cos(phase2)
  51.     z2 = smin2 * sin(phase2)
  52.     x3 = f3 + smaj3 * cos(phase3)
  53.     z3 = smin3 * sin(phase3)
  54.     xm = x3 + mr * cos(phasem)
  55.     zm = z3 + mr * sin(phasem)
  56.     //  See if it is time to output a frame
  57.     if (time >= frametime) then
  58.         nextframe
  59.         //  Display our positions
  60.         print "frame %3.0lf, time %5.1lf (%7.3lf,%7.3lf) (%7.3lf,%7.3lf) (%7.3lf,%7.3lf)",\\
  61.             curframe,time,x1,z1,x2,z2,x2,z3
  62.         //  Generate batch file commands to declare position for frame.
  63.         bwrite "echo #declare x1 = `x1` > orbit.inc"
  64.         bwrite "echo #declare z1 = `z1` >> orbit.inc"
  65.         bwrite "echo #declare x2 = `x2` >> orbit.inc"
  66.         bwrite "echo #declare z2 = `z2` >> orbit.inc"
  67.         bwrite "echo #declare x3 = `x3` >> orbit.inc"
  68.         bwrite "echo #declare z3 = `z3` >> orbit.inc"
  69.         bwrite "echo #declare xm = `xm` >> orbit.inc"
  70.         bwrite "echo #declare zm = `zm` >> orbit.inc"
  71.         //  Generate batch file command to render this frame.
  72.         bwrite "call render orbit orbit`###`"
  73.         //  Remember when to generate next frame
  74.         frametime = frametime + framestep
  75.     endif
  76.     //  Compute distance from focus (the focus is at 0,0)
  77.     d1 = sqrt(x1*x1 + z1*z1)
  78.     d2 = sqrt(x2*x2 + z2*z2)
  79.     d3 = sqrt(x3*x3 + z3*z3)
  80.     //  Compute linear speed based on distance from focus (Kepler's law)
  81.     s1 = atan(1 / d1)
  82.     s2 = atan(1 / d2)
  83.     s3 = atan(1 / d3)
  84.     //  Since we are generating the ellipse from the center rather
  85.     //  than the focus, we must compute the angular speed necessary
  86.      //  to produce the desired linear speed.
  87.     d1 = sqrt((x1-f1)^2 + z1*z1)
  88.     d2 = sqrt((x2-f2)^2 + z2*z2)
  89.     d3 = sqrt((x3-f3)^2 + z3*z3)
  90.     s1 = (sf * s1) / d1
  91.     s2 = (sf * s2) / d2
  92.     s3 = (sf * s3) / d3
  93.     //  Advance angles
  94.     phase1 = mod(phase1 + timestep * s1, 360)
  95.     phase2 = mod(phase2 + timestep * s2, 360)
  96.     phase3 = mod(phase3 + timestep * s3, 360)
  97.     phasem = mod(phasem + timestep * sm, 360)
  98. endfor
  99. //  Put last command in batch file.
  100. epilog
  101. bwrite "call dodta ORBIT /S7"
  102.